package com.chen.controller;

import com.chen.common.Result;

import com.chen.service.IEmpService;
import com.chen.vo.emp.EmpCreateReqVO;
import com.chen.vo.emp.EmpPageReqVO;
import com.chen.vo.emp.EmpUpdateReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 员工表 前端控制器
 * </p>
 *
 * @author chen
 * @since 2024-04-10
 */
@RestController
@RequestMapping("/emps")
@Validated
@Tag(name = "02后台管理-职工管理")
public class EmpController {
    @Resource
    private IEmpService empService;


    @GetMapping
    @Operation(summary = "分页获取员工")
    public Result getPage(@Validated EmpPageReqVO reqVO){
        return empService.getPage(reqVO);
    }

    @DeleteMapping("/{ids}")
    @Operation(summary = "批量删除员工")
    public Result deleteEmpByIds(
            @Parameter(name = "ids",example = "1,2,3") @PathVariable("ids") List<Integer> ids){
        return empService.deleteEmpByIds(ids);
    }

    @PostMapping
    @Operation(summary = "添加员工信息")
    public Result createEmp(@Validated @RequestBody EmpCreateReqVO reqVO){
        return empService.createEmp(reqVO);
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据id获取员工")
    public Result getEmpById(@Parameter(name = "id") @PathVariable("id") Integer id){
        return empService.getEmpById(id);
    }

    @PutMapping
    @Operation(summary = "修改员工")
    public Result updateEmp(@Validated @RequestBody EmpUpdateReqVO reqVO){
        return empService.updateEmp(reqVO);
    }
}
